package com.hdw.med.controller;

import javax.servlet.http.HttpServletRequest;

import com.hdw.common.vo.LayMsg;
import com.hdw.med.bean.model.BaseSd;
import org.springframework.beans.factory.annotation.Autowired;
import com.hdw.common.base.BaseResult;
import com.hdw.common.constant.CommonResultConstant;
import com.hdw.common.base.BaseException;
import com.hdw.med.api.BaseErrlogService;
import com.hdw.med.bean.model.BaseErrlog;
import org.springframework.util.StringUtils;
import com.hdw.common.vo.PaginationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * baseErrlog控制器
 * Created by liujunlei on 2022/01/31.
 */
@RestController
@RequestMapping("/med/baseErrlog/")
@Api(tags="异常日志")
public class BaseErrlogController {

    @Autowired
    BaseErrlogService baseErrlogService;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.GET)
    public LayMsg findByPage(String str, Integer page, Integer limit) {
        PaginationVO<BaseErrlog> pageVO = baseErrlogService.findPageByModel(null, page, limit);
        return LayMsg.success().addCount(pageVO.getTotal()).addData(pageVO.getEntryList());
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="baseErrlog", value="实体", paramType="body", required=true, dataType="BaseErrlog")
    @RequestMapping(value="insert", method=RequestMethod.POST)
    public BaseResult insert(@RequestBody BaseErrlog baseErrlog, HttpServletRequest request)  {
        int num = baseErrlogService.insertSelective(baseErrlog);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="idErrlog", value="主键", paramType="query", required=true, dataType="Long")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(Long idErrlog, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idErrlog)){
            throw new BaseException("请选择要编辑的项");
        }
        BaseErrlog baseErrlog = baseErrlogService.getById(idErrlog);
        return new BaseResult(CommonResultConstant.SUCCESS, baseErrlog);
    }

    @ApiOperation(value="修改")
    @ApiImplicitParam(name="baseErrlog", value="实体", paramType="body", required=true, dataType="BaseErrlog")
    @RequestMapping(value="update", method=RequestMethod.POST)
    public BaseResult update(@RequestBody BaseErrlog baseErrlog, HttpServletRequest request)  {
        int num = baseErrlogService.updateByIdSelective(baseErrlog);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="idErrlog", value="主键", paramType="query", required=true, dataType="Long")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(Long idErrlog, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idErrlog)){
            throw new BaseException("请选择要删除的项");
        }
        int num = baseErrlogService.deleteById(idErrlog);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }
}
